define(["jquery", "easy-admin"], function ($, ea) {
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'product.product/index',
        add_url: 'product.product/add',
        edit_url: 'product.product/edit',
        delete_url: 'product.product/delete',
        export_url: 'product.product/export',
        modify_url: 'product.product/modify',

        detail: 'product.product/detail',
        distribute: 'product.product/distribute',
        cancel: 'product.product/cancel',


    };


    // lay.alert(typelist);
    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                height:750,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'sku', title: 'SKU'},
                    {field: 'unique_code', title: '唯一码',filter:true,sort:false},
                    {field: 'category.name', title: '类别',
                        selectList: ea.getSelectList('Category', 'name'),
                        selectAttribute: 'lay-search',searchOp:'='
                        ,width: 80,},

                    {field: 'supplier.name', title: '已分配',width: 80},
                    {field: 'suppliers', title: '可分配',templet: ea.table.value},

                    {field: 'status', title:'产品状态',width: 100},
                    {field: 'ai_status', title: 'AI状态',width: 100},


                    {field: 'rule.name', title: '规则',minWidth: 80},
                    {field: 'send_time', title: '派单时间',minWidth:80},
                    {field: 'give_time', title: '要求入库时间',minWidth:80},
                    {field: 'is_overtime', title: '是否超时',width: 100,selectList: {0: '未超时', 1: '超时'}, templet: ea.table.list},


                    {
                        width: 200,
                        title: '操作',
                        templet: ea.table.tool,

                        operat: [

                            [{
                                text: '详情',
                                title:'产品详情',
                                url: init.detail,
                                method: 'open',
                                auth: 'detail',
                                class: 'layui-btn layui-btn-success layui-btn-xs',
                                extend: ' data-full="true"',
                            }],[{
                                text: '分派',
                                url: init.distribute,
                                method: 'open',
                                auth: 'distribute',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                            }],[{
                                text: '作废',
                                url: init.cancel,
                                method: 'open',
                                auth: 'cancel',
                                class: 'layui-btn layui-btn-danger layui-btn-xs',
                            }],

                        ]
                    }

                ]],
                customDefaultToolbar:true,
                defaultToolbar: [
                    {
                        title: '搜索',
                        layEvent: 'TABLE_SEARCH',
                        icon: 'layui-icon-search',
                        extend: 'data-table-id="' + init.table_render_id + '"'
                    }
                ],

                filter: {
                    items:['column'],
                    cache: true,
                    bottom: false
                }, done: function (){
                    //穿透 回调 外面的this
                    layui.use(["soulTable"], soulTable => {
                        soulTable.render(this);
                    });
                }
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        detail: function () {
            ea.listen();
        },
        distribute: function () {
            ea.listen();
        },
        cancel: function () {
            ea.listen();
        },
    };
    return Controller;
});